﻿// CLoginDlg.cpp: 实现文件
//

#include "pch.h"
#include "HospitalSystem.h"
#include "CLoginDlg.h"
#include "afxdialogex.h"
#include "admin.h"

// CLoginDlg 对话框

IMPLEMENT_DYNAMIC(CLoginDlg, CDialogEx)

CLoginDlg::CLoginDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_CLoginDlg, pParent)
	, m_user(_T(""))
	, m_pwd(_T(""))
{

}

CLoginDlg::~CLoginDlg()
{
}

void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m_user);
	DDX_Text(pDX, IDC_EDIT2, m_pwd);
}


BEGIN_MESSAGE_MAP(CLoginDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON1, &CLoginDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CLoginDlg::OnBnClickedButton2)
	ON_WM_CLOSE()
END_MESSAGE_MAP()


// CLoginDlg 消息处理程序


void CLoginDlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(true);
	// TODO: 在此添加控件通知处理程序代码
	if (m_user.IsEmpty() || m_pwd.IsEmpty())
	{
		MessageBox(TEXT("输入内容不能为空！"));
		return;
	}

	CAdmin m_set;
	m_set.Open();
	CString str1, str2;
	str1 = m_set.m_UID;
	str2 = m_set.m_PWD;
	if (str1 == m_user)
	{
		if (str2 == m_pwd)
		{

			CDialog::OnCancel();
		}
		else
		{
			MessageBox(L"密码错误！");
		}
	}
	else
	{
		MessageBox(L"不存在该用户！");

	}
	m_set.MoveNext();
}


void CLoginDlg::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	exit(0);
}


void CLoginDlg::OnClose()
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	exit(0);	//结束整个程序
	CDialogEx::OnClose();
}


void CLoginDlg::OnOK()
{
	// TODO: 在此添加专用代码和/或调用基类

	//CDialogEx::OnOK();
}


BOOL CLoginDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	CAdmin m_set;
	CString str;
	str.Format(L"select * from admin");
	m_set.Open(CRecordset::snapshot, str);

	CString str1, str2;
	str1 = m_set.m_UID;
	str2 = m_set.m_PWD;
	m_user = str1;
	m_pwd = str2;
	UpdateData(FALSE);
	// TODO:  在此添加额外的初始化

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}
